package top.ezzz.chats.config;

import lombok.extern.slf4j.Slf4j;
import org.noear.socketd.SocketD;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.event.AppLoadEndEvent;
import org.noear.solon.core.event.EventListener;


@Slf4j
@Component
public class SocketDInit implements EventListener<AppLoadEndEvent> {

    @Inject("${server.port}")
    private int port;

    @Inject
    private SocketDListener listener;


    @Override
    public void onEvent(AppLoadEndEvent appInitEndEvent) throws Throwable {
        //启动服务
        SocketD.createServer("sd:ws")
                .config(c -> c.port(port + 10000))
                .listen(listener)
                .start();
        log.info("启动socketD服务：schema = {} ; port = {}", "sd:ws", port + 10000);
    }
}
